home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.hitl.washington.edu
/
ftp.hitl.washington.edu.tar
/
ftp.hitl.washington.edu
/
pub
/
people
/
tsoper
/
CT Explorer
/
PCIBirdWrapper.cs
< prev
next >
Wrap
Text File
|
2005-05-23
|
15KB
|
464 lines
//PCIBirdWrapper.cs
////////////////////////////////////////////////////////////////////////////////////
// This Wrapper was produced using the pcibird3.h and exporting functions
// to the PCIBirdAPIFuncs.dll which is imported into this wrapper library.
// Modifications were made to allow API function calls in C# using marshaling.
// Not all functionalities were added. None of the Get____Status(), Errorhandling,
// System restore and saving have been implemented. Additionally, the only position
// structure presently supported is the old DOUBLE_POSITION_ANGLES (default) data type
// (Renamed here as 'PositionAnglesReading' class type)
//
// This file is broken into 3 parts: Enumerations, structured classes, and methods.
// Note that the original API reference calls imported here use a slightly different
// name and are augmented with the 'g_' syntax.
////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Text;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace PCIBird
{
//*************************************************************
//** ENUMERATIONS **
//*************************************************************
public enum AGC_MODE_TYPE
{
TRANSMITTER_AND_SENSOR_AGC, // Old style normal addressing mode
SENSOR_AGC_ONLY // Old style extended addressing mode
}
public enum DEVICE_TYPES
{
STANDARD_SENSOR, // standard sensor
TYPE_800_SENSOR, // 8mm sensor
STANDARD_TRANSMITTER, //
MINIBIRD_TRANSMITTER, //
SMALL_TRANSMITTER, // "compact" transmitter
TYPE_500_SENSOR, // 5mm sensor
TYPE_180_SENSOR, // microsensor
UNKNOWN_SENSOR, // default
UNKNOWN_TRANSMITTER // default
}
public enum BOARD_TYPES
{
PCIBIRDII, // <obsolete>
PCIBIRD_STD1, // single standard sensor
PCIBIRD_STD2, // dual standard sensor
PCIBIRD_8mm1, // single 8mm sensor
PCIBIRD_8mm2, // dual 8mm sensor
PCIBIRD_2mm1, // single 2mm sensor (microsensor)
PCIBIRD_2mm2, // dual 2mm sensor (microsensor)
PCIBIRD_UNKNOWN // default
}
public enum SYSTEM_PARAMETER_TYPE
{
SELECT_TRANSMITTER, // short int equal to transmitterID of selected transmitter
POWER_LINE_FREQUENCY, // double value (range is hardware dependent)
AGC_MODE, // enumerated constant of type AGC_MODE_TYPE
MEASUREMENT_RATE, // double value (range is hardware dependent)
MAXIMUM_RANGE, // double value (range is hardware dependent)
METRIC, // boolean value to select metric units for position
END_OF_LIST // end of list place holder
}
public enum SENSOR_PARAMETER_TYPE
{
DATA_FORMAT, // enumerated constant of type DATA_FORMAT_TYPE
ANGLE_ALIGN, // structure of type DOUBLE_ANGLES_RECORD
HEMISPHERE, // enumerated constant of type HEMISPHERE_TYPE
FILTER_AC_WIDE_NOTCH, // boolean value to select/deselect filter
FILTER_AC_NARROW_NOTCH, // boolean value to select/deselect filter
FILTER_DC_ADAPTIVE, // double value in range 0.0 (no filtering) to 1.0 (max)
FILTER_ALPHA_PARAMETERS,// structure of type ADAPTIVE_PARAMETERS
FILTER_LARGE_CHANGE, // boolean value to select/deselect filter
QUALITY, // structure of type QUALITY_PARAMETERS
SERIAL_NUMBER_RX, // attached sensor's serial number
END_OF_RX_LIST
}
public enum XMTR_PARAMETER_TYPE
{
SERIAL_NUMBER_TX, // attached transmitter's serial number
REFERENCE_FRAME, // structure of type DOUBLE_ANGLES_RECORD
XYZ_REFERENCE_FRAME, // boolean value to select/deselect mode
END_OF_TX_LIST
}
public enum BOARD_PARAMETER_TYPE
{
SERIAL_NUMBER_PCB, // installed board's serial number
END_OF_PCB_LIST
}
public enum DATA_FORMAT_TYPE
{
NO_FORMAT_SELECTED=0,
// SHORT (integer) formats
SHORT_POSITION,
SHORT_ANGLES,
SHORT_MATRIX,
SHORT_QUATERNIONS,
SHORT_POSITION_ANGLES,
SHORT_POSITION_MATRIX,
SHORT_POSITION_QUATERNION,
// DOUBLE (floating point) formats
DOUBLE_POSITION,
DOUBLE_ANGLES,
DOUBLE_MATRIX,
DOUBLE_QUATERNIONS,
DOUBLE_POSITION_ANGLES, // system default
DOUBLE_POSITION_MATRIX,
DOUBLE_POSITION_QUATERNION,
// DOUBLE (floating point) formats with time stamp appended
DOUBLE_POSITION_TIME_STAMP,
DOUBLE_ANGLES_TIME_STAMP,
DOUBLE_MATRIX_TIME_STAMP,
DOUBLE_QUATERNIONS_TIME_STAMP,
DOUBLE_POSITION_ANGLES_TIME_STAMP,
DOUBLE_POSITION_MATRIX_TIME_STAMP,
DOUBLE_POSITION_QUATERNION_TIME_STAMP,
// DOUBLE (floating point) formats with time stamp appended and quality #
DOUBLE_POSITION_TIME_Q,
DOUBLE_ANGLES_TIME_Q,
DOUBLE_MATRIX_TIME_Q,
DOUBLE_QUATERNIONS_TIME_Q,
DOUBLE_POSITION_ANGLES_TIME_Q,
DOUBLE_POSITION_MATRIX_TIME_Q,
DOUBLE_POSITION_QUATERNION_TIME_Q,
// These DATA_FORMAT_TYPE codes contain every format in a single structure
SHORT_ALL,
DOUBLE_ALL,
DOUBLE_ALL_TIME_STAMP,
DOUBLE_ALL_TIME_STAMP_Q,
DOUBLE_ALL_TIME_STAMP_Q_RAW, // this format contains a raw data matrix and
// is for factory use only...
MAXIMUM_FORMAT_CODE
}
public enum HEMISPHERE_TYPE
{
FRONT,
BACK,
TOP,
BOTTOM,
LEFT,
RIGHT
}
public enum TRANSMITTER_PARAMETER_TYPE
{
SERIAL_NUMBER_TX, // attached transmitter's serial number
REFERENCE_FRAME, // structure of type DOUBLE_ANGLES_RECORD
XYZ_REFERENCE_FRAME, // boolean value to select/deselect mode
END_OF_TX_LIST
}
//*************************************************************
//** Structured Classes **
//*************************************************************
[StructLayout(LayoutKind.Sequential)]
public class SystemConfig
{
public double measurementRate;
public double powerLineFrequency;
public double maximumRange;
public AGC_MODE_TYPE agcMode;
public int numberBoards;
public int numberSensors;
public int numberTransmitters;
public int transmitterIDRunning;
public int metric;
}
[StructLayout(LayoutKind.Sequential)]
public class XmtrConfig
{
public ulong serialNumber;
public DEVICE_TYPES type;
public int attached;
public ushort boardNumber;
public ushort channelNumber;
}
[StructLayout(LayoutKind.Sequential)]
public class SensorConfig
{
public ushort serialNumber;
public ushort boardNumber;
public ushort channelNumber;
public DEVICE_TYPES type;
public int attached;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public class BoardConfig
{
public ushort serialNumber;
public BOARD_TYPES type;
public ushort revision;
public ushort numberTransmitters;
public ushort numberSensors;
public ushort firmwareNumber;
public ushort firmwareRevision;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=10)]public string modelString;
}
[StructLayout(LayoutKind.Sequential)]
public class PositionAnglesReading
{
public double x;
public double y;
public double z;
public double a;
public double e;
public double r;
}
[StructLayout(LayoutKind.Sequential)]
public class AnglesReading
{
public double a; // azimuth
public double e; // elevation
public double r; // roll
}
[StructLayout(LayoutKind.Sequential)]
public class AdaptiveParameters
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=7)]
public ushort[] alphaMin;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=7)]
public ushort[] alphaMax;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=7)]
public ushort[] vm;
public int alphaOn;
}
[StructLayout(LayoutKind.Sequential)]
public class QualityParameters
{
public ushort errorSlope;
public ushort errorOffset;
public ushort errorSensitivity;
public ushort filterAlpha;
}
//***********************************************************
public class PCIBirdWrapper
{
//Imported DLL functions--------------------------------
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_InitializeSystem();
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_GetSystemConfig(
[MarshalAs(UnmanagedType.LPStruct)]
SystemConfig lpsc );
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_GetXmtrConfig(
uint xmtrID, [In, MarshalAs(UnmanagedType.LPStruct)]
XmtrConfig lpxc);
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_GetSensorConfig(
uint sensorID, [In, MarshalAs(UnmanagedType.LPStruct)]
SensorConfig lpsc);
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_GetBoardConfig(
uint boardID, [In,Out, MarshalAs(UnmanagedType.LPStruct)]
BoardConfig lpbc);
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_GetAsyncSensorReading(
ushort sensorID, [In,Out, MarshalAs(UnmanagedType.AsAny)]
object o, int objectSize );
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_GetSyncSensorReading(
ushort sensorID, [In,Out, MarshalAs(UnmanagedType.AsAny)]
object o, int objectSize);
//------------GetSystemParam METHOD-------------
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_GetSystemParam(
SYSTEM_PARAMETER_TYPE paramType,
[In,Out, MarshalAs(UnmanagedType.AsAny)] object o, int bufferSize);
//----------------------SetSystemParam METHOD-------------
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_SetSystemParam(
SYSTEM_PARAMETER_TYPE paramType,
[In, MarshalAs(UnmanagedType.AsAny)]
object o, int bufferSize);
//------------GetSensorParam METHODS-------------
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_GetSensorParam( //get struct data
ushort sensorID, SENSOR_PARAMETER_TYPE paramType,
[In,Out, MarshalAs(UnmanagedType.AsAny)] object o,
int bufferSize);
//----------------------SetSensorParam METHODS-------------
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_SetSensorParam( //get struct data
ushort sensorID, SENSOR_PARAMETER_TYPE paramType,
[In, MarshalAs(UnmanagedType.AsAny)] object o, int bufferSize);
//------------GetXmtrParam Methods----------------
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_GetXmtrParam( //get struct data
ushort xmtrID, XMTR_PARAMETER_TYPE paramType,
[In,Out, MarshalAs(UnmanagedType.AsAny)] object o, int bufferSize);
//----------------------SetXmtrParam Methods------------------
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_SetXmtrParam(
ushort xmtrID, XMTR_PARAMETER_TYPE paramType,
[In, MarshalAs(UnmanagedType.AsAny)]
object o, int bufferSize);
//----------------------GetBoardParam Methods------------------
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_GetBoardParam( //get struct data
ushort boardID, BOARD_PARAMETER_TYPE paramType,
[In,Out, MarshalAs(UnmanagedType.AsAny)] object o, int bufferSize);
//-------------------------------------------------------------------
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_SetBoardParam(
ushort boardID, BOARD_PARAMETER_TYPE paramType,
[In, MarshalAs(UnmanagedType.AsAny)]
object o);
[DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
public static extern int g_ShutdownSystem();
//Class Methods-----------------------------------------
public int InitializeSystem()
{
return g_InitializeSystem();
}
public SystemConfig GetSystemConfig()
{
SystemConfig systemConfig = new SystemConfig();
int errorCode = g_GetSystemConfig( systemConfig );
return systemConfig;
}
public XmtrConfig GetXmtrConfig(uint xmtrID)
{
XmtrConfig xmtrConfig = new XmtrConfig();
g_GetXmtrConfig(xmtrID,xmtrConfig);
return xmtrConfig;
}
public SensorConfig GetSensorConfig(uint sensorID)
{
SensorConfig sensorConfig = new SensorConfig();
g_GetSensorConfig(sensorID,sensorConfig);
return sensorConfig;
}
public BoardConfig GetBoardConfig(uint boardID)
{
BoardConfig boardConfig = new BoardConfig();
g_GetBoardConfig(boardID,boardConfig);
return boardConfig;
}
public void GetAsyncSensorReading(ushort sensorID, object o, int objectSize)
{
g_GetAsyncSensorReading(sensorID,o,objectSize);
}
public void GetSyncSensorReading(ushort sensorID, object o, int objectSize)
{
g_GetSyncSensorReading(sensorID,o,objectSize);
}
//-------------GetSystemParam-----------------------------------//
public void GetSystemParam(SYSTEM_PARAMETER_TYPE paramType,
object o, int bufferSize)
{
g_GetSystemParam(paramType,o,bufferSize);
}
//-------------SetSystemParam-----------------------------------//
public void SetSystemParam(SYSTEM_PARAMETER_TYPE paramType,
object o, int bufferSize)
{
g_SetSystemParam(paramType,o, bufferSize);
}
//-------------GetSensorParam-----------------------------------//
public void GetSensorParam(ushort sensorID,//structure param
SENSOR_PARAMETER_TYPE paramType, object o, int bufferSize)
{
g_GetSensorParam(sensorID,paramType,o,bufferSize);
}
//------------SetSensorParam------------------------------------//
public void SetSensorParam(ushort sensorID,
SENSOR_PARAMETER_TYPE paramType, object o, int bufferSize)
{
g_SetSensorParam(sensorID,paramType,o,bufferSize);
}
//------------GetXmtrParam------------------------------------//
public void GetXmtrParam(ushort xmtrID, //structure param
XMTR_PARAMETER_TYPE paramType, object o, int bufferSize )
{
g_GetXmtrParam(xmtrID,paramType,o,bufferSize);
}
//------------SetXmtrParam------------------------------------//
public void SetXmtrParam(ushort xmtrID,
XMTR_PARAMETER_TYPE paramType, object o, int bufferSize)
{
g_SetXmtrParam(xmtrID,paramType, o, bufferSize);
}
//------------GetBoardParam------------------------------------//
public void GetBoardParam(ushort boardID, //int param
BOARD_PARAMETER_TYPE paramType, object o, int bufferSize)
{
g_GetBoardParam(boardID,paramType,o,bufferSize);
}
//------------SetBoardParam------------------------------------//
public void SetBoardParam(ushort boardID,
BOARD_PARAMETER_TYPE paramType, object o)
{
g_SetBoardParam(boardID,paramType,o);
}
/// <summary>
/// skipped a bunch of functions right here --> add in later
/// </summary>
public void ShutdownSystem()
{
g_ShutdownSystem();
}
}
}